package com.mashibing.servicemap.remote;

import lombok.extern.slf4j.Slf4j;
import org.mashibing.constant.AmapConfigConstant;
import org.mashibing.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

/**
 * @author:
 * @create: 2024/4/16 10:56
 * @description:
 */
@Component
@Slf4j
public class MapDicDistrictClient {
    @Value("${amap.key}")
    private String amapKey;

    @Autowired
    private RestTemplate restTemplate;

    /**
     * 调用高德行政区划查询服务
     */
    public String dicDistrict(String keywords){
        // 拼接url
        StringBuilder url = new StringBuilder();
        url.append(AmapConfigConstant.DISTRICT_URL);
        url.append("?keywords=").append(keywords);
        url.append("&subdistrict=" + 3);
        url.append("&key=").append(amapKey);
        log.info("url = {}", url);
        // 远程调用
        ResponseEntity<String> forEntity = restTemplate.getForEntity(url.toString(), String.class);

        return forEntity.getBody();
    }
}
